package com.swyc.osschat.Jurisdiction.Controller;

import java.util.Arrays;
import java.util.Map;

import com.swyc.osschat.Common.Base.BaseController;
import com.swyc.osschat.Common.Result.Result;
import com.swyc.osschat.Common.Result.ResultFactory;
import com.swyc.osschat.Common.Util.Page.PageUtils;
import com.swyc.osschat.Common.Util.Page.ValidatorUtils;
import com.swyc.osschat.Jurisdiction.Entity.RoleMenuEntity;
import com.swyc.osschat.Jurisdiction.Service.RoleMenuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("sys/sysrolemenu")
public class SysRoleMenuController extends BaseController<RoleMenuEntity>{
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sysrolemenu:list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = sysRoleMenuService.queryPage(params);
        return ResultFactory.buildSuccessResult(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:sysrolemenu:info")
    public Result info(@PathVariable("id") Integer id){
        RoleMenuEntity sysRoleMenu = sysRoleMenuService.getById(id);
        return ResultFactory.buildSuccessResult(sysRoleMenu);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sysrolemenu:save")
    public Result save(@RequestBody RoleMenuEntity sysRoleMenu){
        boolean flag = sysRoleMenuService.save(sysRoleMenu);
        if (flag){
            return ResultFactory.buildSuccessResult("Success");
        }else {
            return ResultFactory.buildFailResult("Fail");
        }
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sysrolemenu:update")
    public Result update(@RequestBody RoleMenuEntity sysRoleMenu){
        ValidatorUtils.validateEntity(sysRoleMenu);
        boolean flag = sysRoleMenuService.updateById(sysRoleMenu);
        if (flag){
            return ResultFactory.buildSuccessResult("Success");
        }else {
            return ResultFactory.buildFailResult("Fail");
        }
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sysrolemenu:delete")
    public Result delete(@RequestBody Integer[] ids){
        boolean flag = sysRoleMenuService.removeByIds(Arrays.asList(ids));
        if (flag){
            return ResultFactory.buildSuccessResult("Success");
        }else {
            return ResultFactory.buildFailResult("Fail");
        }
    }

}
